Use direct hex decoding for hash strings#33
Merged
Conversation
Copilot created this pull request from a session on behalf of
achamayou
June 5, 2026 13:52
View session
Member
|
Importantly, the code did not check the return value of |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves merkle::HashT hex-string parsing by replacing sscanf-based byte decoding with explicit per-nibble validation/decoding, making invalid and partially-invalid hex strings reliably rejected while supporting mixed-case hex input.
Changes:
- Added a small hex-digit decoder helper and used it to decode hash strings nibble-by-nibble (rejecting any non-hex character or partial byte).
- Extended existing unit tests to cover mixed-case hex parsing.
- Added a dedicated coverage test to exercise valid, mixed-case, and invalid/partially-invalid hash-string parsing paths.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
merklecpp.h |
Replaces sscanf hex parsing with explicit hex digit decoding and validation in HashT string constructor. |
test/unit_tests.cpp |
Adds a mixed-case hash-string constructor test case. |
test/coverage.cpp |
Adds a focused hash-string parsing coverage test and wires it into the coverage test runner. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
achamayou
approved these changes
Jun 5, 2026
maxtropets
approved these changes
Jun 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hash string parsing relied on
sscanfplusstrtoul, requiring an intermediate byte buffer and implicit partial-parse handling. The parser now validates and decodes each hex nibble directly.sscanf/strtoulwith explicit hex digit decoding.